$(function() {

	var rowNum = 1;
	var Extperson; //提取人id

	$("#handdatagrid").datagrid({
		rownumbers: false,
		nowrap: false,
		border: true,
		border: true,
		 width: $(window).width(),
		toolbar: '#eleGridToolbar',
	})
	var handdatagridPanel = $("#handdatagrid").datagrid("getPanel");
	handdatagridPanel.on("click", "a.add", function() {
		$("#eledlgadd").dialog({
			buttons: [{
					text: "添加",
					iconCls: "icon-save",
					handler: function() {
						rowNum = rowNum + 1;
						var table = "<div><table class='form_table' id='eleform_table2" + rowNum + "' border='1' cellspacing='0' cellpadding='0' width='100%' style='border-color: #EEF5FF;'margin-top:15px;'>" +
							"<tr>" +
							"<td id='td_left'  >" +
							"序号：" +
							"</td>" +
							"<td  id='td_right'><input class='easyui-textbox' style='width:100%' readonly='readonly' value=" + rowNum + "></td>" +
							"<td id='td_left'  >" +
							"生物照片：" +
							"</td>" +
							"<td  id='td_right'><input class='easyui-filebox'  name='file' data-options=" + "buttonText:'选择',prompt:'请选择文件...'" + " style='width:100%' /></td>" +
							"<td id='td_left'  >" +
							"物证名称：" +
							"</td>" +
							'<td  class="td_right"><input class="easyui-textbox"  style="width:100%;" /></td>'

							+
							"</tr>" +
							"<tr>" +
							"<td id='td_left'  >" +
							"提取人：" +
							"</td>" +
							"<td><input class='tiquren' id='dioman" + rowNum + "' onclick='addMan(this)' style='width:100%' /></td>"

							+
							"<td id='td_left'  >" +
							"提取日期：" +
							"</td>" +
							"<td><input class='easyui-datebox'  style='width:100%' /></td>" +
							"<td id='td_left'  >遗留部位：</td>" +
							'<td  class="td_right"><input class="easyui-textbox"  style="width:100%;" /></td>' +
							"</tr><tr>" +
							"<td id='td_left'  >类型：</td>" +
							"<td colspan='5'>" +   
							"<label style='margin-left: 20px;'>电子设备</label><input type='radio' checked='checked' name='type" + rowNum + "' value=''>" +
							"<label style='margin-left: 20px;'>电子部件</label><input type='radio' name='type" + rowNum + "' value=''>" +
							"<label style='margin-left: 20px;'>电子设备中存储的数据</label><input type='radio' name='type" + rowNum + "' value=''>" +
							"<label style='margin-left: 20px;'>电子设备传输的电子信息</label><input type='radio' name='type" + rowNum + "' value=''>" +
							"</td>" +

							"</tr><tr><td id='td_left'  >提取方法：</td>" +
							"<td >" +
							'<input class="easyui-textbox"  style="width:100%;" />' +
							"</td>" +
							"<td id='td_left'  >基本特征：</td>" +
							"<td colspan='3'><input class='easyui-textbox'  style='width:100%;' /></td>" +
							"</tr><tr>" +
							
						
							"<td id='td_left'  >	是否列入现场提取登记表：</td>" +
							"<td colspan='5'><input    type='checkbox' name='b' value='1'></td></tr></table></div>"
						$("#eleForm").append(table);
						$.parser.parse($("#eleForm").parent());
					}
				}, {
					text: "删除",
					iconCls: "icon-remove",
					handler: function() {
						if(rowNum == 1) {
							return;
						}
						$("#eleform_table2" + rowNum).remove();
						rowNum = rowNum - 1;
					}
				}, {
					text: "保存",
					iconCls: "icon-save",
					handler: function() {

					}
				}, {
					text: "取消",
					iconCls: "icon-cancel",
					handler: function() {
						$("#eledlgadd").dialog("close");
					}
				}

			]
		});
		$("#eledlgadd").dialog("open").dialog('setTitle', '电子基本信息新增');
	}).on("click", "a.manypicture", function() {
		$("#eledlgpic").dialog({
			buttons: [{
				text: "添加",
				iconCls: "icon-save",
				handler: function() {

				}
			}, {
				text: "取消",
				iconCls: "icon-cancel",
				handler: function() {
					$("#eledlgpic").dialog("close");
				}
			}]
		});
		$("#eledlgpic").dialog("open").dialog('setTitle', '电子物证图片上传');
		$('#elef').textbox('setValue','');
		$('#eleimage').html('');
	});

	
$('#dl12').datalist({
	url: 'json.json',
	method: 'get',
	valueField: 'value',
	textField: 'text',
	lines: false,
	checkbox: false,
	singleSelect: false
});
$('#dl22').datalist({
	//url:'file:///E:/prompt.json',
	//method:'get',	
	valueField: 'value',
	textField: 'text',
	lines: false,
	checkbox: false,
	singleSelect: false
});

//移动按钮
$("#dl_add2").click(function() {
	var rows = $("#dl12").datalist("getSelections");
	/*
	//方式1
	var rowArray = new Array();
	$(rows).each(function(i){
		var value = rows[i].value;
		var text = rows[i].text;
		var row = {
			value:value,
			text:text
		};
		rowArray.push(row);
		//删除
		var rowIndex = $("#dl1").datalist("getRowIndex", rows[i]);
		$("#dl1").datalist("deleteRow",rowIndex);
	});
	rowArray = rowArray.concat($("#dl2").datalist("getRows"));//合并
	var total = { "total":rowArray.length,rows:rowArray };
	$("#dl2").datalist("loadData",rowArray);
	*/
	//方式2
	$(rows).each(function(i) {
		var value = rows[i].value;
		var text = rows[i].text;
		var row = {
			value: value,
			text: text
		};
		//添加
		//$("#dl2").datalist("appendRow",row);
		$("#dl22").datalist("insertRow", {
			index: 0,
			row: row
		}); //作为第一条
		//删除
		var rowIndex = $("#dl12").datalist("getRowIndex", rows[i]);
		$("#dl12").datalist("deleteRow", rowIndex);
	});
	//移动完后重新加载dl2,否则显示不正常
	$("#dl22").datalist("loadData", $("#dl22").datalist('getRows'));
});
//移动按钮
$("#dl_add_all2").click(function() {
	var data = $("#dl12").datalist("getData");
	var rows = data.rows;
	var rowsLength = rows.length;
	var indexArray = new Array();
	for(var i = 0; i < rowsLength; i++) {
		var value = rows[i].value;
		var text = rows[i].text;
		var row = {
			value: value,
			text: text
		};
		//添加
		$("#dl22").datalist("appendRow", row);
	}
	//删除
	var rows = $("#dl12").datalist('getRows');
	for(var i = rows.length - 1; i >= 0; i--) {
		$("#dl12").datalist("deleteRow", i);
	}
	//移动完后重新加载dl2,否则显示不正常
	$("#dl22").datalist("reload");
});
$("#dl_remove2").click(function() {
	var rows = $("#dl22").datalist("getSelections");
	/*
	//方式1
	var rowArray = new Array();
	$(rows).each(function(i){
		var value = rows[i].value;
		var text = rows[i].text;
		var row = {
			value:value,
			text:text
		};
		rowArray.push(row);
		//删除
		var rowIndex = $("#dl2").datalist("getRowIndex", rows[i]);
		$("#dl2").datalist("deleteRow",rowIndex);
	});
	rowArray = rowArray.concat($("#dl1").datalist("getRows"));//合并
	var total = { "total":rowArray.length,rows:rowArray };
	$("#dl1").datalist("loadData",rowArray);
	*/
	//方式2
	var rows = $("#dl22").datalist("getSelections");
	var rowArray = new Array();
	$(rows).each(function(i) {
		var value = rows[i].value;
		var text = rows[i].text;
		var row = {
			value: value,
			text: text
		};
		//添加
		//$("#dl1").datalist("appendRow",row);
		$("#dl12").datalist("insertRow", {
			index: 0,
			row: row
		}); //作为第一条
		//删除
		var rowIndex = $("#dl22").datalist("getRowIndex", rows[i]);
		$("#dl22").datalist("deleteRow", rowIndex);
	});
	//移动完后重新加载dl1,否则显示不正常
	$("#dl12").datalist("loadData", $("#dl12").datalist('getRows'));

});
$("#dl_remove_all2").click(function() {
var data = $("#dl22").datalist("getData");
var rows = data.rows;
var rowsLength = rows.length;
var indexArray = new Array();
for(var i = 0; i < rowsLength; i++) {
	var value = rows[i].value;
	var text = rows[i].text;
	var row = {
		value: value,
		text: text
	};
	//添加
	$("#dl12").datalist("appendRow", row);
}
//删除
var rows = $("#dl22").datalist('getRows');
for(var i = rows.length - 1; i >= 0; i--) {
	$("#dl22").datalist("deleteRow", i);
}
//移动完后重新加载dl1
$("#dl12").datalist("reload");
});
})

function addMan(obj) {
	Extperson = obj.id;
	$("#eledlgMan").dialog({
		buttons: [{
			text: "确定",
			iconCls: "icon-save",
			handler: function() {
				var selVal = '';
				var rows = $("#dl22").datalist('getRows');
				for(var i = 0; i < rows.length; i++) {
					selVal = selVal + rows[i].text + ",";
				};
				var value = selVal.substring(1, selVal.length - 1);
				$('#' + Extperson).val(value);
				$("#eledlgMan").dialog("close");
			}
		}]
	});
	$("#eledlgMan").dialog("open").dialog('setTitle', '选择提取人');
};

//多文件上传
$('#elef').filebox({
	onChange: function(value) {
		var f = $(this).next().find('input[type=file]')[0]; 
		if(f.files && f.files[0]) {
			// 更换图片时清空原图片展示内容
			      
			$('#eleimage').html('');       
			for(var i = 0; i < f.files.length; i++) {        
				var reader = new FileReader(f.files[i]);        
				reader.onload = function(e) {
					//append为在元素中的末尾添加内容
					          
					$('#eleimage').append("<img src='" + e.target.result + "' width='200px' height='100px'>");        
				}        
				reader.readAsDataURL(f.files[i]);
			}    
		}  
	}
})

$("#editHandInfo").click(function() {
	$("#handtableinfo").hide();
	$("#handtableinfo_edit").show();

})
$("#handedit_back").click(function() {
	$("#handtableinfo").show();
	$("#handtableinfo_edit").hide();
})